<?php
/**
 * @version		$Id:  $
 * @package		Success Framework Mobile
 * @subpackage	MainFrame
 * @copyright	Copyright (C) 2007 - 2010 Success company - VietNam. All rights reserved.
 */
defined('PATH_BASE') or die();

class sscls_Router extends sscls_View
{
    //Controller current
    var $controller='index';
    
    //task
    var $task='view';
    
    //View current
    var $view='index';
    
    //Layout current
    var $layout='default';
    
    var $tmpValue=array();
    
    function display($view='index',$layout='default')
    {
        $this->view=$view;
        $this->layout=$layout;
        $this->loadLayout($this->tmpValue);
        return true;
    }
    
    function getView($view='')
    {
        $view=($view!='')?$view:sscls_Request::getVar('view','','GET');
        if($view==''||$view==null)
            $view=sscls_Request::getVar('view','','POST');
            
        if($view==''||$view==null)
            $view='index';
            
        $this->view=$view;
        return  $view; 
    }
    
    function getLayout($layout='')
    {
              
          $layout=($layout!='')?$layout:sscls_Request::getVar('layout','','GET');
          if($layout==''||$layout==null)
            $layout=sscls_Request::getVar('layout','','POST');
          
          if($layout==''||$layout==null)
            $layout='index';
            
          $this->layout=$layout;
          return $layout;
    }
    
    function getController($controller='')
    {
              
          $controller=($controller!='')?$controller:sscls_Request::getVar('c','','GET');
          if($controller==''||$controller==null)
            $controller=sscls_Request::getVar('c','','POST');
          
          if($controller==''||$controller==null)
            $controller='index';
            
          $this->controller=$controller;
          return $controller;
    }
    
    function getTask($task='')
    {
              
          $task=($task!='')?$task:sscls_Request::getVar('t','','GET');
          if($task==''||$task==null)
            $task=sscls_Request::getVar('t','','POST');
          
          if($task==''||$task==null)
            $task='view';
            
          $this->task=$task;
          return $task;
    }
    
    function redirec($url,$msg='',$type='info')
    {
        $session=ss_Main::getSession();
        $session->set('msg_1234567890',$msg);
        $session->set('type_1234567890',$type);

        if (headers_sent()) {
			echo "<script>document.location.href='$url';</script>\n";
		} else {
			//@ob_end_clean(); // clear output buffer
			header( 'HTTP/1.1 301 Moved Permanently' );
			header( 'Location: ' . $url );
		}
    }
    
}
?>